<layout name="page" />
<block name="content">
	<style>
		.ibox-title {
			height: 34px;
		}
		.ibox h5 {
			display: inline-block;
			float: left;
			font-size: 18px;
		}
		.ibox {
			margin-top: 20px;
			padding-bottom: 10px;
			overflow: hidden;
		}
		.ibox-tools {
			float: right;
		}
		.ibox-content {
			padding: 0px;
			padding-bottom: 0px;
		}
		.layui-tab-item {
			padding-top: 10px;
		}
	</style>
	{:widget('page_header/simple',array('name'=>'修改任务'))}
	<div class="operate-panel">
		<a onclick="go_return_url();" class="btn btn-return">返回</a>
	</div>
	<div class="row frame">
		<form method='post' id="form_data" name="form_data" enctype="multipart/form-data"   >
			<input type="hidden" id="ajax" name="ajax" value="0">
			<input type="hidden" id="executor" name="executor" value="{$vo.executor}">
			<input type="hidden" id="opmode" name="opmode" value="add">

			<div class="box col-12">
				<label class="input-label" >标题：</label>
				<div class="input-box">
					{$vo.name}
				</div>
			</div>
			<div class="box col-12">
				<label class="input-label" >发起人：</label>
				<div class="input-box">
					{$vo.user_name}
				</div>
			</div>
			<div class="box col-12">
				<label class="input-label" >发起时间：</label>
				<div class="input-box">
					{:to_date($vo['create_time'],'Y-m-d h:m')}
				</div>
			</div>
			<div class="box col-12">
				<label class="input-label" >谁来执行：</label>
				<div class="input-box">
					{:show_contact($vo['executor'])}
				</div>
			</div>
			<div class="box col-12">
				<label class="input-label" >期望完成时间：</label>
				<div class="input-box">
					{:substr($vo['expected_time'],0,16)}
				</div>
			</div>
			<div class="box col-12">
				<label class="input-label" >任务描述：</label>
				<div class="input-box">
					<div class="content-wrap">
						{$vo.content}
					</div>
				</div>
			</div>
			<div class="box col-12">
				<label class="input-label" >附件：</label>
				{:widget('file_upload/view',array('add_file'=>$vo['add_file'],'mode'=>'show'))}
			</div>
		</form>
	</div>
	{:widget('page_header/sub',array('name'=>'任务执行情况'))}
	<div class="table">
		<ul>
			<li class="thead">
				<span class="w9 text-center">指派给</span>
				<span class="w6 text-center">状态</span>
				<span class="w6 text-center">执行人</span>
				<span class="w13 text-center">计划完成时间</span>
				<span class="w13 text-center">已完成情况</span>
				<span class="w13 pull-right">附件</span>
				<span class="x1">执行内容</span>
			</li>
			<volist name="task_log" val="item">
				<li class="tbody">
					<span class="col-9 text-center">&nbsp;{$item.executor_name}</span>
					<span class="col-6 text-center">&nbsp;{$item.status|task_status}</span>
					<span class="col-6 text-center">&nbsp;{$item.transactor_name}&nbsp;</span>
					<span class="col-13 text-center">&nbsp;{$item.plan_time|substr=0,16}&nbsp;</span>
					<span class="col-13 text-center"> &nbsp;
						<eq name='item.status' value='10'>
							{$item.finish_rate|finish_rate}
						</eq>
						<egt name='item.status' value='20'>
							{$item.finish_time|substr=0,16}
						</egt>&nbsp;</span>
					<span class="col-13 pull-right"> {:W('FileUpload/link',array($item['add_file']))} </span>

					<span class="auto">
						<div style="overflow:hidden">
							{$item.feed_back}
						</div> </span>
				</li>
			</volist>
		</ul>
	</div>
	<eq name="is_working" value="1">
		<div class="ibox task_todo ibox layui-tab">
			<div class="ibox-title">
				<h5>我的执行情况</h5>
				<div class="ibox-tools no-border">
					<ul class="layui-tab-title">
						<li class="layui-this" id="working">
							执行情况
						</li>
						<li id="forword">
							转交任务
						</li>
						<li id="reject">
							拒绝接受
						</li>
					</ul>
				</div>
			</div>
			<div class="layui-tab-content ibox-content">
				<div class="layui-tab-item layui-show">
					<form method='post' id="form_data_working" name="form_data_working" >
						<input type="hidden" name="status" value="10">
						<input type="hidden" name="id" value="{$task_working.id}">
						<div class="frame">
							<div class="bit-2">
								<div class="layui-form-item">
									<label class="layui-form-label" >计划完成时间：</label>
									<div class="layui-input-block">
										<input class="input-date-time layui-input" id="plan_time" name="plan_time" value="{$task_working.plan_time|substr=0,16}" check="required" info="请输入计划完成时间" readonly="readonly">
									</div>
								</div>
							</div>
							<div class="bit-2">
								<div class="layui-form-item">
									<label class="layui-form-label" >完成率：</label>
									<div class="layui-input-block col-8">
										<span class="postfix">%</span>
										<input type="text" id="finish_rate" name="finish_rate" class="layui-input" value="{$task_working.finish_rate|default=0}"/>
									</div>
								</div>
							</div>
						</div>
						<div class="frame">
							<div class="bit-1">
								<div class="layui-form-item">
									<label class="layui-form-label" >执行内容：</label>
									<div class="layui-input-block">
										<textarea id="feed_back" name="feed_back" class="input-textarea simple " style="height:130px">{$task_working.feed_back}</textarea>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" for="name">附件：</label>
									<div class="layui-input-block">
										{:W('FileUpload/edit',array($task_working['add_file']))}
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
				<div class="layui-tab-item">
					<form method='post' id="form_data_forword" name="form_data_forword" >
						<input type="hidden" name="id" value="{$task_working.id}">
						<input type="hidden" name="task_id" value="{$task_working.task_id}">
						<input type="hidden" name="status" value="21">
						<input type="hidden" id="forword_executor" name="forword_executor" >
						<div class="frame">
							<div class="bit-1">
								<div class="layui-form-item">
									<label class="layui-form-label" for="name">转交给：</label>
									<div class="layui-input-block">
										<div id="actor_wrap" class="input-box">
											<a class="add-on" onclick="popup_actor();"><i class="fa fa-user"></i> </a>
											<div class="wrap" >
												<span class="address_list"></span>
												<span class="text" >
													<input class="letter" type="text"  >
												</span>
											</div>
											<div class="search dropdown ">
												<ul class="dropdown-menu"></ul>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="bit-1">
								<div class="layui-form-item">
									<label class="layui-form-label" >执行内容：</label>
									<div class="layui-input-block">
										<textarea id="feed_back" name="feed_back" class="simple" style="height:120px" check="required" info="请输入执行内容">{$task_working.feed_back}</textarea>
										<p></p>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
				<div class="layui-tab-item">
					<form method='post' id="form_data_reject" name="form_data_reject" >
						<input type="hidden" name="status" value="22">
						<input type="hidden" name="id" value="{$task_working.id}">
						<div class="frame">
							<div class="bit-1">
								<div class="layui-form-item">
									<label class="layui-form-label" >执行内容：</label>
									<div class="layui-input-block">
										<textarea id="feed_back" name="feed_back" class="simple" style="height:120px" >{$task_working.feed_back}</textarea>
										<p></p>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
			<div class="frame">
				<div class="bit-1">
					<div class="layui-input-block">
						<a onclick="save_log();" class="btn  col-6">提交</a>
						<a onclick="go_return_url();" class="btn btn-cancel">取消</a>
					</div>
				</div>
			</div>
		</div>
	</eq>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global', 'element', 'editor'], function() {
			var $ = layui.jquery;

			//set_val('status', '{$task_working.finish_rate}');

			$(document).on("click", ".inputbox .address_list a.del", function() {
				$(this).parent().parent().remove();
			});

			function save_log() {
				$status_name = $(".task_todo li.layui-this").attr('id');
				console.log($status_name);
				if ($status_name == "forword") {
					if ($(".address_list span").length == 0) {
						layer.msg('请选择要转交的人');
						return false;
					} else {
						$("#forword_executor").val("");
						$("#actor_wrap span.address_list span").each(function() {
							$("#forword_executor").val($("#forword_executor").val() + $(this).find("b").text() + '|' + $(this).attr("data") + ";");
						});
					}

					layer.msg('转交以后不能修改了,是否提交?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function() {
							$form_name = "form_data_" + $status_name;
							send_form($form_name, "{:U('save_log')}", "{:U('index')}", function(ret) {
								if (ret.status) {
									layer.msg(ret.info, function() {
										location.reload(true);
									});
								} else {
									layer.msg(ret.info);
									return false;
								}
							});
						},
						no : function(index) {
							layer.close(index);
							return false;
						}
					});
				};

				if ($status_name == "reject") {
					layer.msg('选择拒绝以后不能修改了,是否提交?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function() {
							$form_name = "form_data_" + $status_name;
							send_form($form_name, "{:U('save_log')}", "{:U('index')}", function(ret) {
								if (ret.status) {
									layer.msg(ret.info, function() {
										location.reload(true);
									});
								} else {
									layer.msg(ret.info);
									return false;
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				};
				if ($status_name == "working") {

					var $finish = eval(document.getElementById('finish_rate')).value
					if ($finish > 100) {
						layer.msg("完成率填写错误")
					} else {

						$form_name = "form_data_" + $status_name;
						send_form($form_name, "{:U('save_log')}", "{:U('index')}", function(ret) {
							if (ret.status) {
								layer.msg(ret.info, function() {
									location.reload(true);
								});
							} else {
								layer.msg(ret.info);
								return false;
							}

						});
					};
				};

			};
			window.save_log = save_log;
		});

		function accept($task_log_id) {
			send_ajax("{:U('accept')}", 'task_log_id=' + $task_log_id, function(data) {
				if (data.status) {
					layer.msg(data.info, function() {
						location.reload(true);
					});
				};
			});
		};

		function popup_actor() {
			winopen("{:U('popup/task')}", 560, 470);
		};

		function let_me_do($task_id) {
			send_ajax("{:U('let_me_do')}", 'task_id=' + $task_id, function(data) {
				if (data.status) {
					layer.msg(data.info, function() {
						location.reload(true);
					});
				};
			});
		};

	</script>
</block>
